home *** CD-ROM | disk | FTP | other *** search
- Path: erich.triumf.ca!bennett
- From: bennett@erich.triumf.ca (P.Bennett)
- Newsgroups: comp.lang.c
- Subject: Re: Help! Can't read input from keyboard!
- Date: 1 Apr 1996 22:40 PST
- Organization: TRIUMF: Tri-University Meson Facility
- Distribution: world
- Message-ID: <1APR199622404442@erich.triumf.ca>
- References: <4jq0ts$5mh@taniemarie.solon.com>
- NNTP-Posting-Host: ftp.triumf.ca
- News-Software: VAX/VMS VNEWS 1.50
-
- In article <4jq0ts$5mh@taniemarie.solon.com>, seebs@taniemarie.solon.com (Peter Seebach) writes...
- >I guess I thought I knew C, but maybe not. The following program compiles
- >without error with
- >
- >gcc -g -O -Wa,ll -Wshadow -Wpointer-arith -Wcast-qual -Wstrict-prototypes -Wmissing-prototypes
- >
- >but doesn't print 3! I thought scanf and printf were asymptotic.
-
-
- It would help if you posted the _real_ code so we would know there weren't any
- typos...
-
- > #include <stdio.h>
- >
- > int main(void) {
- > int i = 0;
- >
- > (void) sscanf, "3", "%d", i;
-
- This won't compile as is - it needs some parentheses, like:
- (void) sscanf("3", "%d", i);
- If this is what your real code says, then you need to change it to:
- (void) sscanf("3", "%d", &i);
- Since sscanf() must change i, you have to pass i's _address_, using &i.
-
-
- >
- > (void) printf, "%d", i;
- this must have some parentheses as well:
- (void) printf("%d", i);
-
- The arguments for the sscanf() and printf() families are similar, but not
- identical - scanf() needs the _address_ of its arguments, and printf() does
- not. There are also some differences in the format specifiers.
-
-
- Peter Bennett VE7CEI | Vessels shall be deemed to be in sight
- Internet: bennett@triumf.ca | of one another only when one can be
- Packet: ve7cei@ve7kit.#vanc.bc.ca | observed visually from the other
- TRIUMF, Vancouver, B.C., Canada | ColRegs 3(k)
- GPS and NMEA info and programs: ftp://sundae.triumf.ca/pub/peter/index.html
- or: ftp://ftp-i2.informatik.rwth-aachen.de/pub/arnd/GPS/peter/index.html
-
-